package top.wangjiu.reactive.rpc.handler;


import lombok.Getter;
import top.wangjiu.reactive.rpc.model.RpcRequest;
import top.wangjiu.reactive.rpc.model.RpcResponse;

import java.util.function.Supplier;

/**
 * @ClassName AbstractResultTypeHandler
 * @Description TODO
 * @Author wangjiu
 * @Date 2021/8/3 4:47 下午
 */
public abstract class AbstractRequestHandler<T> implements RequestHandler<T> {

    private ResultInvoker<T> invoker;

    private ResultWriter writer;

    @Override
    public void setInvoker(ResultInvoker invoker) {
        this.invoker = invoker;
    }

    @Override
    public void setResultWriter(ResultWriter writer) {
        this.writer = writer;
    }

    protected T invoke(RpcRequest request) throws Exception{
        return this.invoker.invoke(request);
    }

    protected void write(RpcResponse response){
        writer.writeResult(response);
    }

}
